package com.bb.blog.security.client;

import lombok.RequiredArgsConstructor;

import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
//public class RedisOAuth2AuthorizationRequestRepository implements AuthorizationRequestRepository<OAuth2AuthorizationRequest> {
public class RedisOAuth2AuthorizationRequestRepository{
//    private final String redisAttributeName = RedisOAuth2AuthorizationRequestRepository.class.getName() + ".AUTHORIZATION_REQUEST";
//
//    private final RedisTemplate<Object,Object> redisTemplate;
//
//    private static  Long VALID_TIME = 5 * 60L;
//
//    /**
//     * 认证code 的有效时间 默认300秒
//     * @param validTime
//     */
//    @Value(value = "${auth.code.validTime:300}")
//    public static void setValidTime(Long validTime) {
//        VALID_TIME = validTime;
//    }
//
//    @Override
//    public OAuth2AuthorizationRequest loadAuthorizationRequest(HttpServletRequest request) {
//        String stateParameter = this.getStateParameter(request);
//        if (stateParameter != null) {
//            String key = redisAttributeName + stateParameter;
//            return (OAuth2AuthorizationRequest) redisTemplate.opsForValue().get(key);
//        }
//        return null;
//    }
//
//    @Override
//    public void saveAuthorizationRequest(OAuth2AuthorizationRequest authorizationRequest, HttpServletRequest request, HttpServletResponse response) {
//        String stateParameter = authorizationRequest.getState();
//        if (stateParameter != null) {
//
//            String key = redisAttributeName + stateParameter;
//
//            redisTemplate.opsForValue().set(key, authorizationRequest, VALID_TIME, TimeUnit.SECONDS);
//        }
//    }
//
//    @Override
//    public OAuth2AuthorizationRequest removeAuthorizationRequest(HttpServletRequest request) {
//        String stateParameter = this.getStateParameter(request);
//        if(stateParameter != null){
//            String key = redisAttributeName + stateParameter;
//            OAuth2AuthorizationRequest authReq = this.loadAuthorizationRequest(request);
//            redisTemplate.delete(key);
//            return authReq;
//        }
//        return null;
//    }
//
//    /**
//     * Gets the state parameter from the {@link HttpServletRequest}
//     *
//     * @param request the request to use
//     * @return the state parameter or null if not found
//     */
//    private String getStateParameter(HttpServletRequest request) {
//        return request.getParameter(OAuth2ParameterNames.STATE);
//    }
}
